lexer grammar Wiki;

options{
    superClass = WikiLexerBase;
}

TITLE: {getLine() == 1}? WHOLE_LINE {输出标题();} NEWLINE;

BOLD: {getCharPositionInLine() > 0}? '*' {加粗开始();} ~'*'+ {加粗结束();} '*' ;

ITALICS: '_' {斜体开始();} ~'_'+ {斜体结束();} '_' ;

LINK: '@' {地址开始();} ~[@|]+ {地址结束();} '|' {链接标题开始();} ~'@'+ {链接标题结束();} '@';

H1: {getCharPositionInLine()==0}? '### ' {标题开始(1);} WHOLE_LINE {标题结束();} NEWLINE ;
H2: {getCharPositionInLine()==0}? '## ' {标题开始(2);} WHOLE_LINE {标题结束();} NEWLINE;
H3: {getCharPositionInLine()==0}? '# ' {标题开始(3);} WHOLE_LINE {标题结束();} NEWLINE;

PARAGRAPH: NEWLINE NEWLINE { 结束List(); ; 输出("\r\n<p>");};

UL: '* ' { 开始List(); };

TABLE: {开始表格();} '[' {输出("<table border=1>\r\n");} 
           {输出("<tr>\r\n");} {输出("<td>\r\n");} (TABLE | BOLD | ITALICS | {!即将结束列()}? {L();} ELSE {R();})+  ('|' {输出("<td>\r\n");} (TABLE | BOLD | ITALICS | {!即将结束列()}? {L();} ELSE {R();})+ )* {输出("\r\n</tr>\r\n");} 
           (
               NEWLINE '--' NEWLINE {输出("<tr>\r\n");} {输出("<td>\r\n");} (TABLE | BOLD | ITALICS | {!即将结束列()}? {L();} ELSE {R();})+   ('|' {输出("<td>\r\n");} (TABLE | BOLD | ITALICS | {!即将结束列()}? {L();} ELSE {R();})+  )* {输出("\r\n</tr>");}
           )* NEWLINE {输出("\r\n");}
       ']' {输出("</table>\r\n"); 结束表格();};

fragment
WHOLE_LINE: ~[\r\n]* ;

fragment
NEWLINE: '\r'? '\n' ;

ELSE: . {输出(getText());};



